package com.kacheap.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.kacheap.service.DisruptorMqService;

/**
 * @author lixing
 * @version 1.0
 * @description: TODO
 * @date 2023/11/24 0024 23:06:32
 */
@RestController
@RequestMapping("/disruptor/")
public class TestController {
    @Autowired
    private DisruptorMqService disruptorMqService;

    /**
     * 访问地址： http://127.0.0.1:8080/disruptor/test
     *
     * @param:
     * @return: java.lang.String
     */
    @GetMapping("test")
    public String test() throws Exception {
        disruptorMqService.sayHelloMq("Message execute");
        return "Successfult";
    }

    /**
     * 多线程循环调用
     * http://127.0.0.1:8080/disruptor/test1?num=10
     *
     * @param num
     * @return
     * @throws Exception
     */
    @GetMapping("test1")
    public String test1(@RequestParam(value = "num") int num) throws Exception {
        long start = System.currentTimeMillis();
        for (int i = 0; i < num; i++) {
            disruptorMqService.sayHelloMq("Message execute");
        }
        long end = System.currentTimeMillis();
        long time_consuming = end - start;
        return "处理" + num + "个线程总共耗时" + time_consuming + "毫秒";
    }

}
